<?php
error_reporting(0);
set_time_limit(9999999);
date_default_timezone_set (PRC);
include("../common/config.php");
$db=new connectDb();
$url="http://www.zccw.info/index";


for($i=1;$i<48;$i++){
	
	$urls=$url."/page/".$i;
	
	//echo $urls."<br>";
	
	$page=file_get_contents($urls);
	
	$page=DeleteHtml($page);
		
	$now=date('Y-m-d',time());
	
	//echo $d;exit();
	
	//echo $page;
	
	preg_match_all("/<h2 class=\"entry-title\">(.*?)<\/tr><\/table><\/div><\/div>/is",$page,$temp);
	
	//var_dump($temp[1]);
	
	for($n=0;$n<50;$n++){
		
		//var_dump($temp[1][$n]);
		
		if($temp[1][$n]=="")break;
		
		preg_match("/<spanclass=\"result-id\">(.*?)<\/h2>/is",$temp[1][$n],$temp_title);
		
		//var_dump($temp_title[1]);
		
		preg_match("/<\/a><spanclass=\"time\">(.*?)<\/span>/is",$temp_title[1],$time);
		
		$time=gTime($time[1]);
		
		//echo $time[1]."<br>";
		//echo $time[1]."ooo".$now."<br>";
		//if($time!=$now)break 2;
		
		preg_match("/<\/span><ahref=\"(.*?)\" title=\"/is",$temp_title[1],$title_link);
		
		//var_dump($title_link[1]);
		
		preg_match("/rel=\"noreferrer\">(.*?)<\/a><spanclass=\"time\">/is",$temp_title[1],$title);
		
		//echo $title[1]."<br>";
		
		//echo $temp[1][$n];

		preg_match("/<spanclass=\"cat-links\">(.*?)<spanclass=\"tag-links\">/is",$temp[1][$n],$temp_tag);
		
		//var_dump($temp_tag[1]);
		
		preg_match("/\">(.*?)<\/a><\/span><spanclass=\"entry-utility-prep food_name\">/is",$temp_tag[1],$area);
		
		//echo $area[1];
		
		preg_match("/rel=\"tag\">(.*?)<\/a>/is",$temp_tag[1],$food);
		
		preg_match("/<spanclass=\"other-links\">(.*?)<spanclass=\"entry-utility-prep author-tag\">/is",$temp[1][$n],$from_all);
		
		preg_match_all("/rel=\"tag\">(.*?)<\/a>/is",$from_all[1],$from);
		
		$from=hebin($from[1]);
		
		//echo $from;
		
		preg_match("/<spanclass=\"entry-utility-prep entry-utility-prep-tag-links\">(.*?)<\/span><\/span><spanclass=\"other-links\">/is",$temp[1][$n],$tag_all);
		
		preg_match_all("/rel=\"tag\">(.*?)<\/a>/is",$tag_all[1],$tag);
		
		$tag=hebin($tag[1]);
		
		//echo $food[1];
		
		//var_dump($tag_all[1]);
		
		//var_dump($from[1]);
		
		$x=mysql_query("insert into food_caiji_zccw (id,news_title,news_link,news_time,create_time,area,food,tags,`from`)values(null,'$title[1]','$title_link[1]','$time',now(),'$area[1]','$food[1]','$tag','$from')")or die(mysql_error());
		}
		
	}
	
	
function DeleteHtml($str) { 
	$str = trim($str); 
	//$str = strip_tags($str,""); 
	$str = str_replace("\t","",$str); 
	$str = str_replace("\r\n","",$str); 
	$str = str_replace("\r","",$str); 
	$str = str_replace("\n","",$str); 
	$str = str_replace(" "," ",$str); 
	return trim($str); 
}


function hebin($array){
	for($i=0;$i<1000;$i++){
		if($array[$i]=="")break;
		if($i==0){$value=$array[$i];}else{
	$value.="|".$array[$i];}
		}
	return $value;
	}


function gTime($time){
	$y=substr($time,0,4);
	
	$m=substr($time,5,2);
	
	$d=substr($time,8,2);
	
	$time=$y."-".$m."-".$d;
	
	return $time;
	}
?>